package com.dankegongyu.lib.share;

import android.content.Context;
import android.text.TextUtils;

import com.dankegongyu.lib.share.bean.DKShareImage;
import com.dankegongyu.lib.share.bean.DKShareMiniProgram;
import com.dankegongyu.lib.share.bean.DKShareWeb;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMMin;
import com.umeng.socialize.media.UMWeb;

/**
 * @author wpq
 * @version 1.0
 */
class DKUmMediaFactory {

    /**
     * web
     */
    static UMWeb createUMWeb(DKShareWeb dkShareWeb) {
        Context context = dkShareWeb.getActivity();
        UMImage thumb = null;
        if (dkShareWeb.getShareImage() != null) {
            thumb = new UMImage(context, dkShareWeb.getShareImage());
        } else if (!TextUtils.isEmpty(dkShareWeb.getShareImageUrl())) {
            thumb = new UMImage(context, dkShareWeb.getShareImageUrl());
        } else if (dkShareWeb.getShareImageIcon() != 0) {
            thumb = new UMImage(context, dkShareWeb.getShareImageIcon());
        }
        UMWeb web = new UMWeb(dkShareWeb.getShareUrl());
        web.setTitle(dkShareWeb.getShareTitle()); //标题
        web.setDescription(dkShareWeb.getShareContent()); //描述
        web.setThumb(thumb); //缩略图
        return web;
    }

    /**
     * image
     */
    static UMImage createUMImage(DKShareImage dkShareImage) {
        Context context = dkShareImage.getActivity();
        UMImage image = null;
        UMImage thumb = null;
        if (dkShareImage.getBitmap() != null) {
            image = new UMImage(context, dkShareImage.getBitmap());
            thumb = new UMImage(context, dkShareImage.getBitmap());
        } else if (dkShareImage.getFile() != null) {
            image = new UMImage(context, dkShareImage.getFile());
            thumb = new UMImage(context, dkShareImage.getFile());
        } else if (dkShareImage.getBytes() != null) {
            image = new UMImage(context, dkShareImage.getBytes());
            thumb = new UMImage(context, dkShareImage.getBytes());
        } else if (!TextUtils.isEmpty(dkShareImage.getImageUrl())) {
            image = new UMImage(context, dkShareImage.getImageUrl());
            thumb = new UMImage(context, dkShareImage.getImageUrl());
        } else if (dkShareImage.getImageRes() != 0) {
            image = new UMImage(context, dkShareImage.getImageRes());
            thumb = new UMImage(context, dkShareImage.getImageRes());
        }
        if (image != null) {
            // 压缩格式设置：
            image.compressStyle = UMImage.CompressStyle.SCALE;//大小压缩，默认为大小压缩，适合普通很大的图
            image.compressStyle = UMImage.CompressStyle.QUALITY;//质量压缩，适合长图的分享
            image.setThumb(thumb);
            image.setTitle(dkShareImage.getShareTitle());
            image.setDescription(dkShareImage.getShareContent());
        }
        return image;
    }

    /**
     * 小程序
     */
    static UMMin createUMMin(Context context, DKShareMiniProgram miniProgram) {
        UMImage thumb = null;
        if (miniProgram.getShareImage() != null) {
            thumb = new UMImage(context, miniProgram.getShareImage());
        } else if (!TextUtils.isEmpty(miniProgram.getShareImageUrl())) {
            thumb = new UMImage(context, miniProgram.getShareImageUrl());
        } else if (miniProgram.getShareImageIcon() != 0) {
            thumb = new UMImage(context, miniProgram.getShareImageIcon());
        }
        UMMin umMin = new UMMin(miniProgram.getShareUrl());
        umMin.setTitle(miniProgram.getShareTitle());
        umMin.setDescription(miniProgram.getShareContent());
        umMin.setThumb(thumb);
        umMin.setPath(miniProgram.getPath());
        umMin.setUserName(miniProgram.getUserName());
        return umMin;
    }
}
